CONTENTS | INDEX | PREV | NEXT
 stat

 NAME
  stat - stat a file by name

 SYNOPSIS
  #include <sys/stat.h>

  int error = stat(name, &stat_buf);
  const char *name;
  struct stat stat_buf;

 FUNCTION
  stat() is a unix compatible call that returns information
  pertaining to the file represented by its name.

  If 0 is returned, the call succeeded and the fields will be
  filled in as follows:

      st_mode     flags:  S_IFDIR if directory
                  S_IFREG if regular file
                  S_IREAD if readable
                  S_IWRITE    if writable
                  S_IEXEC if executable

      st_size     size of the file, in bytes

      st_blksize      512 (for now)

      st_blocks       a guess at the number of actual blocks the
              file takes up, including headers & side sectors

      st_ctime        time the file was last modified

      st_mtime        same as st_ctime

      st_dev      physical device ID (do not try to interpret this
              field, but it does represent the dos handler)

      st_ino      inode ID (usually a file block number on the amiga)


 NOTE
  On the amiga one normally cannot directly examine a file that
  is exclusively locked.  If this case occurs, stat() will attempt
  to scan the parent directory for the file and if *that* doesn't
  work, returns -1.


 INPUTS
  char *name;     name of file to stat

  struct stat *sbuf;  address of stat structure that will be filled in

 RESULTS
  int error;      0 on success, < 0 on error
  none

 EXAMPLE
  #include <stdio.h>
  #include <fcntl.h>
  #include <sys/stat.h>

  main(ac, av)
  int ac;
  char *av[];
  {
      int r;
      struct stat stat_buf;

      if (ac == 1) {
      puts("test scratch_file");
      exit(1);
      }
      r = stat(av[1], &stat_buf);
      if (r < 0)
      printf("Can't stat %sn", av[1]);
      else
      printf("File is %d bytes longn", stat_buf.st_size);
      return(0);
  }

 SEE ALSO
  chdir